用在封裝 Publisher 並 函式化的目的, 使用型別抹除的方式, 將 中間的 Operator 抹除, 但是仍保留 Operator 的功能.
func makeTimerPublisher(time:TimeInterval) -> AnyPublisher<Date,Never> {
return Timer.publish(every: 1, on: RunLoop.main, in: .common)
.print()
.eraseToAnyPublisher()
}
無 Rarbles demo!
這類型的很簡單, 就是使用 Swift 透過 Python api 直接向 LLVM 溝通. 要注意的是: 這類型還是需要用 subscriber 才能觸發.
前綴參數
限制是 String.func print(_ prefix: String = "", to stream: TextOutputStream? = nil) -> Publishers.Print<Self>
多解釋無義.
就像是 raise(SIGINT)
!
import XCTest
let await = XCTestExpectation()
let pst = PassthroughSubject<Int,Error>()
pst
.breakpoint()
.print()
.sink(receiveCompletion: {print($0)}, receiveValue: {print($0)})
.store(in: &subscriptionSet)
pst.send(1) //Entering Debuging mode
pst.send(completion: .failure(URLError(.badURL)))
await.fulfill()
wait(for: [await], timeout: 5)
import XCTest
let await = XCTestExpectation()
let pst = PassthroughSubject<Int,Error>()
pst
.breakpointOnError()
.print()
.sink(receiveCompletion: {print($0)}, receiveValue: {print($0)})
.store(in: &subscriptionSet)
pst.send(1)
pst.send(completion: .failure(URLError(.badURL))) //Entering Debuging mode
await.fulfill()
wait(for: [await], timeout: 5)
RELEASE/DEBUG
的前置處理器差異, 但也不能干預下游.func handleEvents(receiveSubscription:,
receiveOutput:,
receiveCompletion:,
receiveCancel:,
receiveRequest:) -> Publishers.HandleEvents<Self>
很直覺的 API, 就不多做解釋了.